/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import com.thoughtworks.xstream.XStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author thedaego
 */
public class WebResource
{
    private String resourceName;
    private List<DataLocator> dataLocators = new ArrayList();

    public WebResource(String resourceName, List<DataLocator> dataLocators) {
        this.resourceName = resourceName;
        this.dataLocators = dataLocators;
    }
    
    public WebResource(String resourceName, DataLocator dataLocator) {
        this.resourceName = resourceName;
        this.dataLocators.add(dataLocator);
    }
    public WebResource(String name) {
        this.resourceName = name;
    }

    public void setDataLocators(List<DataLocator> dataLocators) {
        this.dataLocators = dataLocators;
    }


    public void addDataLocator(DataLocator locator){
        this.dataLocators.add(locator);
    }
    public String getName() {
        return resourceName;
    }

    public void setName(String name) {
        this.resourceName = name;
    }

    public List<DataLocator> getDataLocators(){
        return this.dataLocators;
    }
    /**
     * Load this web resource from the webresources.xml file
     */
    public static WebResource load(String name) throws FileNotFoundException, URISyntaxException{
        XStream xstream = new XStream();
        URL xmlUrl = ClassLoader.getSystemResource("webresources.xml");
        FileReader fReader = new FileReader(new File(xmlUrl.toURI()));
        WebResource wr = (WebResource)xstream.fromXML(fReader);
        return wr;
    }

}
